

import 'package:p_location/alarm/constant/alarm_http_url.dart';
import 'package:p_location/alarm/res/alarm_vehicle_res.dart';
import 'package:p_location/alarm/widget/alarm_vehicle_list_item.dart';
import 'package:p_location/common/obj/dept_filter_option.dart';
import 'package:p_location/common/ui/base_filter_head_list_view.dart';
import 'package:p_location/net/dio_http_client.dart';

class AlarmVehicleListPage extends BaseFilterHeadListView {

  final bool isFromSearch;
  final bool isHiddenAppbar;
  final bool isHiddenBack;

  @override
  BaseFilterHeadListViewState<BaseFilterHeadListView> getState() {
    return _FilterHeadListViewState();
  }

  const AlarmVehicleListPage(
      {this.isFromSearch = false, this.isHiddenAppbar = true,this.isHiddenBack = true})
      : super(isHiddenAppbar: isHiddenAppbar,isHiddenBack: isHiddenBack);
}

class _FilterHeadListViewState
    extends BaseFilterHeadListViewState<AlarmVehicleListPage> {
  bool nextPageFlag = false;

  @override
  void initState() {
    super.initState();
//    _requestAccidentTypeFilters();
  }

  @override
  initDropMenus() {
    initDropMenuView(0, [
      DeptFilterOption(deptCode: '', deptName: '全部'),
      DeptFilterOption(deptCode: '1', deptName: '车辆越界报警'),
      DeptFilterOption(deptCode: '2', deptName: '车辆滞留报警'),
      DeptFilterOption(deptCode: '8', deptName: '车辆超速报警')
    ]);
    initDropMenuView(1, [
      DeptFilterOption(deptCode: '', deptName: '全部'),
      DeptFilterOption(deptCode: '1', deptName: '报警中'),
      DeptFilterOption(deptCode: '0', deptName: '已处理')
    ]);
  }

  @override
  List<String> getTabTitles() {
    return ['报警类型','报警状态'];
  }

  @override
  String getTitle() {
    return '车辆报警';
  }

  @override
  List<String> getFilterKeys() {
    return ['alarmType','status'];
  }

  @override
  bool hasNextPage() {
    return nextPageFlag;
  }

  @override
  getActions() {
    return [];
  }

  @override
  void realRequest() async {
//    params["page"] = 1;
//    params["size"] = 15;
//    if(params["carType"] == "全部"){
//      params["carType"] = "";
//    }
    await DioHttpClient.requestPost(
        context, AlarmHttpUrl.ALARM_VEHICLE_LIST_URL, params, this);
  }

  @override
  List getList(response) {
    if (response != null && response.data != null) {
      AlarmVehicleRes listRes = AlarmVehicleRes.fromJson(response.data);
      if (listRes != null && listRes.data != null) {
        nextPageFlag = !((listRes.length/pageNum) + 1 >= currPage);
        return listRes.data;
      }
    }
    return [];
  }

  @override
  createListViewItem(index) {
    return AlarmVehicleListItem(lists[index]);
  }

//  _requestAccidentTypeFilters() async {
//    Map<String, dynamic> params = {};
//    params["page"] = 1;
//    params["size"] = 10;
//    await DioHttpClient.requestPost(context, AlarmHttpUrl.ALARM_VEHICLE_TYPE_LIST_URL,
//        params, new NetListenerImpl(onSuccess, onError),contentType: NetConstants.POST_TYPE_FORM);
//  }
//
//  void onSuccess(Response response) {
//    setState(() {
//      if (response != null && response.data != null) {
//        FilterVehicleTypeRes res = FilterVehicleTypeRes.fromJson(response.data);
//        if (res != null && res.data != null) {
//          print('取到了1');
//          res.data.insert(0, FilterVehicleType(wheelDiameter: '', name: '全部'));
//          initDropMenuView(0, res.data);
//        }
//      }
//    });
//  }
//
//  void onError(CommonRes errorRes) {}
}
